document.addEventListener("DOMContentLoaded", function () {
    let input = document.getElementById("inputreadId");
    $.ajax({
        url: "/reader/getReadId",
        type: "POST",
        success: function (readId) {
            input.value = readId;
        },
        error: function (error) {
            console.log("请求出错：", error);
        }
    });
});

$('#loginButton').click(function (event) {
    event.preventDefault();
    var oldPass = $('#inputoldPass').val();
    var newPass= $('#inputnewPass').val();
    var againNewPass = $('#againInput').val();
    var readId = $('#inputreadId').val();
    $.ajax({
        type: 'POST',
        url: '/reader/updatepass',
        contentType: 'application/x-www-form-urlencoded',
        data: { oldPass: oldPass, newPass: newPass, againNewPass: againNewPass, readId: readId},
        success: function (response) {
            if (response === '1') {
                alert('修改成功，请重新登陆');
                window.location.href = "./goOut"
            } else if (response === '2') {
                alert('两次新密码不一致');
            } else if (response === '3') {
                alert('旧密码错误');
            } else {
                alert('未知的返回结果，请联系管理员！');
            }
        },
        error: function () {
            alert('请求发生错误，请稍后再试！');
        }
    });
});